package com.xayy.ds.controller;

import cn.kawins.base.result.ResultBody;
import com.xayy.mgt.model.vo.NodeTreeInfoVo;
import com.xtck.ha.common.core.constant.HttpStatus;
import com.xtck.ha.common.core.utils.poi.ExcelUtil;
import com.xtck.ha.common.core.web.controller.BaseController;
import com.xtck.ha.common.core.web.domain.AjaxResult;
import com.xtck.ha.common.core.web.page.TableDataInfo;
import com.xayy.ds.model.DsEquipTreeInfo;
import com.xayy.ds.service.DsEquipTreeInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 模型列表 controller
 *
 * @ClassName: DsEquipTreeInfoController
 * @Description: 外部访问接口
 * @author liuyuan
 * @date 2025-07-03
 */
@Api(tags = "设备树信息表管理")
@RestController
@RequestMapping("/api/v1.0/equipTree")
public class DsEquipTreeInfoController extends BaseController {

    @Autowired
    private DsEquipTreeInfoService dsEquipTreeInfoService;


    @ApiOperation("分页查询设备树信息表列表")
    @GetMapping("/page")
    public AjaxResult page(DsEquipTreeInfo dsEquipTreeInfo)
    {
        startPage();
        List<DsEquipTreeInfo> list = dsEquipTreeInfoService.selectTList(dsEquipTreeInfo);
        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(HttpStatus.SUCCESS);
        rspData.setList(list);
        rspData.setMsg("查询成功");
        rspData.setTotal(dsEquipTreeInfoService.count(dsEquipTreeInfo));
        return AjaxResult.success(rspData);
    }

    @ApiOperation("列表查询设备树信息表")
    @GetMapping("/list")
    public List<DsEquipTreeInfo> list(DsEquipTreeInfo dsEquipTreeInfo)
    {
        List<DsEquipTreeInfo> list = dsEquipTreeInfoService.selectTList(dsEquipTreeInfo);
        return list;
    }

    @ApiOperation("导出设备树信息表列表")
    @PostMapping("/export")
    public void export(HttpServletResponse response, DsEquipTreeInfo dsEquipTreeInfo)
    {
        List<DsEquipTreeInfo> list = dsEquipTreeInfoService.selectTList(dsEquipTreeInfo);
        ExcelUtil<DsEquipTreeInfo> util = new ExcelUtil<>(DsEquipTreeInfo.class);
        util.exportExcel(response, list, "样例数据");
    }

    @ApiOperation("获取$设备树信息表详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(dsEquipTreeInfoService.selectTById(id));
    }

    @ApiOperation("新增$设备树信息表")
    @PostMapping
    public AjaxResult add(@RequestBody DsEquipTreeInfo dsEquipTreeInfo)
    {
        return toAjax(dsEquipTreeInfoService.insertT(dsEquipTreeInfo));
    }

    @ApiOperation("修改设备树信息表")
    @PutMapping
    public AjaxResult update(@RequestBody DsEquipTreeInfo dsEquipTreeInfo)
    {
        int i = dsEquipTreeInfoService.updateT(dsEquipTreeInfo);
        return toAjax(i);
    }

//    @ApiOperation("删除设备树信息表")
//	@DeleteMapping("/{ids}")
//    public AjaxResult remove(@PathVariable Long[] ids)
//    {
//        return toAjax(dsEquipTreeInfoService.deleteTByIds(ids));
//    }


    @GetMapping("/getEquipTree")
    @ApiOperation(value = "获取全部节点数据(左侧树)", httpMethod = "GET", response = NodeTreeInfoVo.class, notes = "装备树")
    public ResultBody getEquipTree() {
        return dsEquipTreeInfoService.getEquipTree().body();
    }

    @PostMapping("/addOrUpdate")
    @ApiOperation(value = "新增/更新树节点(左侧树)", httpMethod = "POST")
    public ResultBody addOrUpdate(@RequestBody DsEquipTreeInfo equipTreeInfo) {
        return dsEquipTreeInfoService.addOrUpdate(equipTreeInfo).body();
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除树节点(左侧树)", httpMethod = "DELETE")
    public ResultBody delete(@PathVariable Long id) {
        return dsEquipTreeInfoService.deleteTreeById(id).body();
    }

    @GetMapping("/getEquipNodeTree")
    @ApiOperation(value = "获取全部节点数据(左侧树加一层卫星)", httpMethod = "GET", response = NodeTreeInfoVo.class)
    public ResultBody getEquipNodeTree() {
        return dsEquipTreeInfoService.getEquipNodeTree().body();
    }

    @GetMapping("/getEquipNodeTreeForNumber")
    @ApiOperation(value = "获取节点数据层级N-number", httpMethod = "GET", response = NodeTreeInfoVo.class)
    public ResultBody getEquipNodeTreeForNumber(@RequestParam("number") Integer number) {
        return dsEquipTreeInfoService.getEquipNodeTreeForNumber(number).body();
    }


}
